package com.uenpay.im.ui.old.activity.wallet;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @copyright http://www.qiyunxin.com
 * 
 */
public class BalanceRedInvokItem extends HttpInvokeItem {

	public class BalanceRedInvokItemResult extends HttpInvokeResult {
		public String balance;
		public int _haspaypassword;
	}

	public BalanceRedInvokItemResult getOutput() {
		return (BalanceRedInvokItemResult) GetResultObject();
	}

	public BalanceRedInvokItem() {
		String url = APIConfiguration.getBaseUrl()
				+ "Purse/Purse/purse?"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		BalanceRedInvokItemResult result = new BalanceRedInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonObject = json.optJSONObject("data");
			if (jsonObject == null) {
				return result;
			}
			result.balance = jsonObject.optString("amount");
			/** 是否设置支付密码 **/
			result._haspaypassword = jsonObject.optInt("_haspaypassword");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
